// 获取对象内数据
function getObjectValue (object, key) {
    if (!Array.isArray(object) && typeof object !== 'object') return object
    return key.split('.').reduce(function(obj, key) {
        if (!obj) return null
        if (Array.isArray(obj)) {
            return obj[key] || null
        }
        return Reflect.get(obj, key) || null;
    }, object);
}

function to(url) {
    if (url === '') return
    window.location.href = url
}

function base64ToFile(currentValue) {
    if (/base64/.test(currentValue)) {
        const data = currentValue.split(',');
        const mime = data[0].match(/:(.*?);/)[1];
        const binary = atob(data[1].trim());
        let n = binary.length;
        const u8arr = new Uint8Array(n);
        while (n--) {
            u8arr[n] = binary.charCodeAt(n);
        }
        return new File([u8arr], `${new Date().getTime()}.png`, {type: mime})
    }
    return null
}

// 获取get参数
function getUrlParams(name) {
    let reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i")
    let r = window.location.search.substr(1).match(reg)
    if (r != null) return unescape(r[2])
    return null
}


function getNowFormatDate(yearOffset = 0) {
    let date = new Date();
    let year = date.getFullYear() + yearOffset;
    let month = date.getMonth() + 1;
    let day = date.getDate();

    let hours = new Date().getHours()
    let minutes = new Date().getMinutes()
    let seconds = new Date().getSeconds()

    if (month >= 1 && month <= 9) {
        month = `0${month}`
    }

    if (day >= 1 && day <= 9) {
        day = `0${day}` ;
    }

    return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`
}